package com.controller;

import com.entity.TeacherTable;
import com.server.ITeacherTableService;
import com.util.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author chenhailong
 * @ClassName: ITTreeNodeController
 * @Description: 多数据源测试
 * @date 2021/12/20 19:17
 * @Version 1.0
 */
@RestController
@RequestMapping("/teacher")
@Api(tags = "老师请求类", value = "老师")
public class TeacgerController {


    @Autowired
    private ITeacherTableService teacherTableService;

    /**
     * @param teacherTable teacherTable
     * @return response response
     * @Author chl
     * @Description 新增功能
     * @Date 19:19 2021/12/20
     **/
    @PostMapping("/add")
    @ApiOperation(value = "新增老师")
    public Response add(@RequestBody TeacherTable teacherTable) {
        return teacherTableService.add(teacherTable);

    }

    /**
     * @param teacherTable teacherTable
     * @return response response
     * @Author chl
     * @Description sql示例
     * @Date 9:16 2022/10/12
     **/
    @PostMapping("/selectList")
    @ApiOperation(value = "查询老师")
    public Response selectList(@RequestBody TeacherTable teacherTable) {
        List<TeacherTable> list = teacherTableService.selectList(teacherTable);

        return Response.createSuccess("成功", list);
    }

    /**
     * @param teacherTable teacherTable
     * @return response response
     * @Author chl
     * @Description sql示例
     * @Date 9:16 2022/10/12
     **/
    @PostMapping("/batchAdd")
    @ApiOperation(value = "批量新增")
    public Response batchAdd(@RequestBody TeacherTable teacherTable) {
        List<Long> list = teacherTableService.batchAdd(teacherTable);
        return Response.createSuccess("成功", list);
    }

    @PostMapping("/multithreadingAdd")
    @ApiOperation(value = "多线程新增数据")
    public Response multithreadingAdd() {

        return Response.createSuccess("成功", teacherTableService.multithreadingAdd());
    }


    @PostMapping("/multithreadingSelect")
    @ApiOperation(value = "多线程查询数据")
    public Response multithreadingSelect() {
        // 方法一
//        List<TeacherTable> teacherTables = teacherTableService.multithreadingSelect();

        // 方法二
        List<TeacherTable> teacherTables = teacherTableService.multithreadingSelect2();

        // 方法三
//        List<TeacherTable> teacherTables = teacherTableService.multithreadingSelect3();

        return Response.createSuccess("成功",teacherTables);
    }
}
